package com.magic.gre.mvp.presenter;

import com.google.gson.reflect.TypeToken;
import com.magic.gre.entity.WordsDetailsBean;
import com.magic.gre.entity.base.BaseListModel;
import com.magic.gre.entity.base.BaseObjectModel;
import com.magic.gre.mvp.contract.WordsDetailsContract;
import com.magic.gre.mvp.model.WordsDetailsModelImpl;
import com.noname.lib_base_java.mvp.BasePresenterImpl;

/**
 * Author: Lmoumou
 * Date: 2019-01-08 11:53
 * 文件名: WordsDetailspresenterImpl
 * 描述:
 */
public class WordsDetailspresenterImpl extends BasePresenterImpl<WordsDetailsContract.View, WordsDetailsContract.Model>
        implements WordsDetailsContract.Presenter {
    public WordsDetailspresenterImpl(WordsDetailsContract.View view) {
        super(view);
    }

    @Override
    protected WordsDetailsContract.Model creatModel() {
        return new WordsDetailsModelImpl();
    }

    @Override
    public void pUnitDetails(String unitId) {
        mModel.mUnitDetails(new CommonObserver<BaseListModel<WordsDetailsBean>>(new TypeToken<BaseListModel<WordsDetailsBean>>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseListModel<WordsDetailsBean> wordsBeanBaseListModel) {
                mView.vUnitDatails(wordsBeanBaseListModel.body);
            }

            @Override
            public void onError(int status, String msg) {

            }
        }, unitId);
    }

    @Override
    public void pNewWordsSave(String vocabularyId, final int position) {
        mModel.mNewWordsSave(new CommonObserver<BaseObjectModel>(new TypeToken<BaseObjectModel>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel baseObjectModel) {
                mView.vNewWordsSave(position);
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        }, vocabularyId);
    }

    @Override
    public void pRipeWordsSave(String vocabularyId, final int position) {
        mModel.mRipeWordsSave(new CommonObserver<BaseObjectModel>(new TypeToken<BaseObjectModel>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel baseObjectModel) {
                mView.vRipeWordsSave(position);
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        }, vocabularyId);
    }

    @Override
    public void pRecordSave(String id, String unitId) {
        mModel.mRecordSave(new CommonObserver<BaseObjectModel>(new TypeToken<BaseObjectModel>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel baseObjectModel) {
                mView.vRecordSave();
            }

            @Override
            public void onError(int status, String msg) {

            }
        }, id, unitId);
    }

    @Override
    public void pCountToDay() {
        mModel.mCountToDay(new CommonObserver<BaseObjectModel<String>>(new TypeToken<BaseObjectModel<String>>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel<String> stringBaseObjectModel) {
                mView.vCountToDay(stringBaseObjectModel.body);
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        });
    }

    @Override
    public void pLearnRecordUpdate(String id) {
        mModel.mLearnRecordUpdate(new CommonObserver<BaseObjectModel>(new TypeToken<BaseObjectModel>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel baseObjectModel) {

            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        }, id);
    }

    @Override
    public void pCreat() {
        mModel.mCreat(new CommonObserver<BaseObjectModel<String>>(new TypeToken<BaseObjectModel<String>>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel<String> stringBaseObjectModel) {
                mView.vCreat(stringBaseObjectModel.body);
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        });
    }

    @Override
    public void pLastUnit(String unitId) {
        mModel.mLastUnit(new CommonObserver<BaseObjectModel<String>>(new TypeToken<BaseObjectModel<String>>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel<String> baseObjectModel) {
                mView.vLastUnit(baseObjectModel.body);
            }

            @Override
            public void onError(int status, String msg) {

            }
        }, unitId);
    }
}
